<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>地图导航</title>
  <style>
    *{
      margin:0;
      padding:0;
    }
    #container{
      width:100%;
      height:100vh;
      background-color:pink;
    }
  </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
  window._AMapSecurityConfig = {
    securityJsCode: "2f6ae7b085a71e320bc47e2a322ca096",
  };
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=8645cb4ce9842f630d1adaef13b899e7"></script>
<script type="text/javascript">
  var zoom = 14
  var map = new AMap.Map("container", {
    zoom: zoom,
    center:[116.397658,39.908028] ,//地图中心点坐标
  })

  function setLocation(lon, lat) {
    map.setZoomAndCenter(zoom,[lon,lat])

    var marker = new AMap.Marker({
        map: map,
        icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
        position: [lon, lat]
    })

    map.add(marker)

    map.plugin(['AMap.PlaceSearch'], function() {
      var PlaceSearchOptions = { //设置PlaceSearch属性
        map:map,//在地图中显示对应的标记
        pageSize: 4, //每页结果数,默认10
        pageIndex: 1, //请求页码，默认1
        extensions: "base" //返回信息详略，默认为base（基本信息）
      };
      var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
        AMap.Event.addListener(MSearch, "complete",(result)=>{
        //调用鸿蒙端的方法，现在最近的几个地址
         window.swift.receiveNearPlace(JSON.stringify(result.poiList.pois))
      }); //返回结果
      MSearch.searchNearBy("停车场", [lon, lat]); //关键字查询
    });
  }


  window.onload=function(){
    //调用鸿蒙端的业务方法
    window.swift.setCurrentLocation()
  }

</script>
</body>
</html>